package com.qingzhou;

import cn.hutool.core.lang.Console;
import cn.hutool.core.util.StrUtil;
import com.qingzhou.common.utils.ContextUtil;
import lombok.SneakyThrows;
import org.noear.solon.Solon;
import org.noear.solon.SolonProps;
import org.noear.solon.admin.client.annotation.EnableAdminClient;
import org.noear.solon.admin.server.annotation.EnableAdminServer;
import org.noear.solon.annotation.SolonMain;
import org.noear.solon.core.handle.Context;
import org.noear.solon.scheduling.annotation.EnableAsync;
import org.noear.solon.scheduling.annotation.EnableScheduling;

import java.net.InetAddress;

/**
 * 启动程序
 * @author xm
 */
//@EnableAdminClient
//@EnableAdminServer
@EnableAsync
@EnableScheduling
@SolonMain
public class QingZhouBootApplication {

    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        SolonProps cfg = Solon.start(QingZhouBootApplication.class, args).cfg();
        long times = System.currentTimeMillis() - start;
        Console.log("临床电子信息采集系统（EDC）启动成功，耗时:【" + times + "ms】");
        Console.log("主页：http://{}:{}/index.html", getLocalIpAddress(), cfg.serverPort());
        Console.log("接口：http://{}:{}/doc.html", getLocalIpAddress(), cfg.serverPort());
        String db = StrUtil.replace(cfg.get("solon.dataSources.data_source!.master.jdbcUrl"), "jdbc:mysql://", "");
        Console.log("数据库：{}", StrUtil.subBefore(db, "?", true));
    }

    @SneakyThrows
    private static String getLocalIpAddress() {
        InetAddress inetAddress = InetAddress.getLocalHost();
        return inetAddress.getHostAddress();
    }

    private static void printDivider() {
        Console.log("========================================");
    }
}
